package com.hzau.tourist_service_sys.comtroller;

import com.hzau.tourist_service_sys.pojo.Complaint;
import com.hzau.tourist_service_sys.result.Result;
import com.hzau.tourist_service_sys.service.ComplaintService;
import com.hzau.tourist_service_sys.ultils.jjwttool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileNotFoundException;
import java.io.IOException;

@RestController

public class ComplaintController {
    @Autowired
    ComplaintService complaintService;
    //提交投诉
    @PostMapping("/feedback/fileUpload")
    public Result fileUpload(@RequestPart(value = "files") MultipartFile multipartFile) throws IOException {
        return complaintService.fileUpload(multipartFile);
    }
    @PostMapping("/feedback/submitcomplaints")
    public Result insertComplaint(
            @RequestBody Complaint complaint, @RequestHeader("token") String token) throws IOException {
//        System.out.println(complaint);


        long id=jjwttool.getUserId(token);

        return complaintService.complaintInsert(complaint,id);

    }
    //查询分页
    @PostMapping("/feedback/cpFindPage1")
    public Result findComplaintbypage(/*Integer pagenum, @RequestPart(required = false) Integer status, @RequestPart(required = false) String userName*/
                                        @RequestBody Complaint complaint) throws FileNotFoundException {

        return complaintService.findAllComplaintByPage(complaint);
    }
    //查询投诉详情
    @GetMapping("/feedback/selectByContentId/{contentId}")
    public Result findfComplaintbyId(@PathVariable long contentId){
        return complaintService.findComplaintById(contentId);
    }
    //更新状态
    @PostMapping("feedback/cpSetChecked")
    public  Result upadteStatusByid(@RequestBody Complaint complaint){

        return  complaintService.updateStatusById(complaint.getCpId(),complaint.getSolveStatus());
    }
    //更新回复
    @PostMapping("/feedback/replyUpdate")
    public Result replyUpdate(@RequestBody Complaint complaint){
        return  complaintService
                .replyUpdte(complaint);
    }

}

